﻿using Microsoft.VisualBasic;
using System;
using System.Data;
using System.Globalization;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace APP.HELPER.Utils.CustomizeToolbox
{
    public enum EnumCurrency
    {
        VND,
        USD
    }
   
    public static class GridCalendarControlLib
    {
        private static string _Currency = "VND";
        private static string _currencySymbol = "đồng";
        private static string _UnitSecond = "";
        public static string CurrencySymbol
        {
            get
            {
                return GridCalendarControlLib._currencySymbol;
            }
            set
            {
                GridCalendarControlLib._currencySymbol = value;
            }
        }
        public static string Currency
        {
            get
            {
                return GridCalendarControlLib._Currency;
            }
            set
            {
                GridCalendarControlLib._Currency = value;
            }
        }
        public static string UnitSecond
        {
            get
            {
                return GridCalendarControlLib._UnitSecond;
            }
            set
            {
                GridCalendarControlLib._UnitSecond = value;
            }
        }
        public static void AddCalender(DataGridView dt, string ColumnName)
        {
            DataGridViewCalendarColumn dataGridViewCalendarColumn = new DataGridViewCalendarColumn();
            dataGridViewCalendarColumn.HeaderText = ColumnName;
            dataGridViewCalendarColumn.Name = ColumnName;
            dt.Columns.Add(dataGridViewCalendarColumn);
        }
        public static void AddCalender(DataGridView dt, string ColumnName, string Caption)
        {
            DataGridViewCalendarColumn dataGridViewCalendarColumn = new DataGridViewCalendarColumn();
            dataGridViewCalendarColumn.HeaderText = ColumnName;
            dataGridViewCalendarColumn.Name = ColumnName;
            dataGridViewCalendarColumn.HeaderText = Caption;
            dt.Columns.Add(dataGridViewCalendarColumn);
        }
        public static void AddCalender(DataGridView dt, string ColumnName, string Caption, bool ReadOnly)
        {
            DataGridViewCalendarColumn dataGridViewCalendarColumn = new DataGridViewCalendarColumn();
            dataGridViewCalendarColumn.HeaderText = ColumnName;
            dataGridViewCalendarColumn.Name = ColumnName;
            dataGridViewCalendarColumn.HeaderText = Caption;
            dataGridViewCalendarColumn.ReadOnly = ReadOnly;
            dataGridViewCalendarColumn.ValueType = typeof(DateTime);
            dt.Columns.Add(dataGridViewCalendarColumn);
        }
        public static void AddCalender(DataGridView dt, string ColumnName, string Caption, bool ReadOnly, string Format)
        {
            DataGridViewCalendarColumn dataGridViewCalendarColumn = new DataGridViewCalendarColumn();
            dataGridViewCalendarColumn.HeaderText = ColumnName;
            dataGridViewCalendarColumn.Name = ColumnName;
            dataGridViewCalendarColumn.HeaderText = Caption;
            dataGridViewCalendarColumn.ReadOnly = ReadOnly;
            dataGridViewCalendarColumn.DefaultCellStyle.Format = Format;
            dataGridViewCalendarColumn.ValueType = typeof(DateTime);
            dt.Columns.Add(dataGridViewCalendarColumn);
        }
        public static void AddCalender(DataGridView dt, string ColumnName, string Caption, bool ReadOnly, string Format, DataGridViewContentAlignment Aligment)
        {
            DataGridViewCalendarColumn dataGridViewCalendarColumn = new DataGridViewCalendarColumn();
            dataGridViewCalendarColumn.HeaderText = ColumnName;
            dataGridViewCalendarColumn.Name = ColumnName;
            dataGridViewCalendarColumn.HeaderText = Caption;
            dataGridViewCalendarColumn.ReadOnly = ReadOnly;
            dataGridViewCalendarColumn.DefaultCellStyle.Format = Format;
            dataGridViewCalendarColumn.DefaultCellStyle.Alignment = Aligment;
            dataGridViewCalendarColumn.ValueType = typeof(DateTime);
            dt.Columns.Add(dataGridViewCalendarColumn);
        }
        public static void AddCalender(DataGridView dt, string ColumnName, string Caption, bool ReadOnly, string Format, DataGridViewContentAlignment Aligment, bool Visible)
        {
            DataGridViewCalendarColumn dataGridViewCalendarColumn = new DataGridViewCalendarColumn();
            dataGridViewCalendarColumn.HeaderText = ColumnName;
            dataGridViewCalendarColumn.Name = ColumnName;
            dataGridViewCalendarColumn.HeaderText = Caption;
            dataGridViewCalendarColumn.ReadOnly = ReadOnly;
            dataGridViewCalendarColumn.DefaultCellStyle.Format = Format;
            dataGridViewCalendarColumn.ValueType = typeof(DateTime);
            dataGridViewCalendarColumn.DefaultCellStyle.Alignment = Aligment;
            dataGridViewCalendarColumn.Visible = Visible;
            dt.Columns.Add(dataGridViewCalendarColumn);
        }
        public static void AddTextBox(DataGridView dt, DataGridViewTextBoxColumn col)
        {
            dt.Columns.Add(col);
        }
        public static void AddTextBox(DataGridView dt, string ColumnName)
        {
            DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn.HeaderText = ColumnName;
            dataGridViewTextBoxColumn.Name = ColumnName;
            dt.Columns.Add(dataGridViewTextBoxColumn);
        }
        public static void AddTextBox(DataGridView dt, string ColumnName, string Caption)
        {
            DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn.HeaderText = ColumnName;
            dataGridViewTextBoxColumn.Name = ColumnName;
            dataGridViewTextBoxColumn.HeaderText = Caption;
            dt.Columns.Add(dataGridViewTextBoxColumn);
        }
        public static void AddTextBox(DataGridView dt, string ColumnName, string Caption, int Width)
        {
            DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn.HeaderText = ColumnName;
            dataGridViewTextBoxColumn.Name = ColumnName;
            dataGridViewTextBoxColumn.HeaderText = Caption;
            dataGridViewTextBoxColumn.Width = Width;
            dt.Columns.Add(dataGridViewTextBoxColumn);
        }
        public static void AddTextBox(DataGridView dt, string ColumnName, string Caption, int Width, bool ReadOnly)
        {
            DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn.HeaderText = ColumnName;
            dataGridViewTextBoxColumn.Name = ColumnName;
            dataGridViewTextBoxColumn.HeaderText = Caption;
            dataGridViewTextBoxColumn.Width = Width;
            dataGridViewTextBoxColumn.ReadOnly = ReadOnly;
            dt.Columns.Add(dataGridViewTextBoxColumn);
        }
        public static void AddTextBox(DataGridView dt, string ColumnName, string Caption, int Width, bool ReadOnly, string Format)
        {
            DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn.HeaderText = ColumnName;
            dataGridViewTextBoxColumn.Name = ColumnName;
            dataGridViewTextBoxColumn.HeaderText = Caption;
            dataGridViewTextBoxColumn.Width = Width;
            dataGridViewTextBoxColumn.ReadOnly = ReadOnly;
            dataGridViewTextBoxColumn.DefaultCellStyle.Format = Format;
            dt.Columns.Add(dataGridViewTextBoxColumn);
        }
        public static void AddTextBox(DataGridView dt, string ColumnName, string Caption, int Width, bool ReadOnly, string Format, DataGridViewContentAlignment Alignment)
        {
            DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn.HeaderText = ColumnName;
            dataGridViewTextBoxColumn.Name = ColumnName;
            dataGridViewTextBoxColumn.HeaderText = Caption;
            dataGridViewTextBoxColumn.Width = Width;
            dataGridViewTextBoxColumn.ReadOnly = ReadOnly;
            dataGridViewTextBoxColumn.DefaultCellStyle.Format = Format;
            dataGridViewTextBoxColumn.DefaultCellStyle.Alignment = Alignment;
            dt.Columns.Add(dataGridViewTextBoxColumn);
        }
        public static void AddTextBox(DataGridView dt, string ColumnName, string Caption, int Width, bool ReadOnly, string Format, DataGridViewContentAlignment Alignment, int _Type)
        {
            DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn.HeaderText = ColumnName;
            dataGridViewTextBoxColumn.Name = ColumnName;
            dataGridViewTextBoxColumn.HeaderText = Caption;
            dataGridViewTextBoxColumn.Width = Width;
            dataGridViewTextBoxColumn.ReadOnly = ReadOnly;
            if (_Type == 0)
            {
                dataGridViewTextBoxColumn.ValueType = typeof(int);
            }
            else
            {
                if (_Type == 1)
                {
                    dataGridViewTextBoxColumn.ValueType = typeof(double);
                }
                else
                {
                    dataGridViewTextBoxColumn.ValueType = typeof(DateTime);
                }
            }
            dataGridViewTextBoxColumn.DefaultCellStyle.Format = Format;
            dataGridViewTextBoxColumn.DefaultCellStyle.Alignment = Alignment;
            dt.Columns.Add(dataGridViewTextBoxColumn);
        }
        public static void AddTextBox(DataGridView dt, string ColumnName, string Caption, int Width, bool ReadOnly, string Format, bool Visible)
        {
            DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn.HeaderText = ColumnName;
            dataGridViewTextBoxColumn.Name = ColumnName;
            dataGridViewTextBoxColumn.HeaderText = Caption;
            dataGridViewTextBoxColumn.Width = Width;
            dataGridViewTextBoxColumn.ReadOnly = ReadOnly;
            dataGridViewTextBoxColumn.DefaultCellStyle.Format = Format;
            dataGridViewTextBoxColumn.Visible = Visible;
            dt.Columns.Add(dataGridViewTextBoxColumn);
        }
        public static void AddCheckBox(DataGridView dt, DataGridViewCheckBoxColumn col)
        {
            dt.Columns.Add(col);
        }
        public static void AddCheckBox(DataGridView dt, string ColumnName)
        {
            GridCalendarControlLib.AddCheckBox(dt, new DataGridViewCheckBoxColumn
            {
                HeaderText = ColumnName,
                Name = ColumnName,
                TrueValue = 1,
                FalseValue = 0
            });
        }
        public static void AddCheckBox(DataGridView dt, string ColumnName, string Caption)
        {
            DataGridViewCheckBoxColumn col = new DataGridViewCheckBoxColumn();

            GridCalendarControlLib.AddCheckBox(dt, new DataGridViewCheckBoxColumn
            {
                HeaderText = Caption,
                Name = ColumnName,
                TrueValue = 1,
                FalseValue = 0
            });
        }
        public static void AddCheckBox(DataGridView dt, string ColumnName, string Caption, int wdith)
        {
            GridCalendarControlLib.AddCheckBox(dt, new DataGridViewCheckBoxColumn
            {
                HeaderText = Caption,
                Name = ColumnName,
                Width = wdith,
                TrueValue = 1,
                FalseValue = 0
            });
        }
        public static void AddComboBox(DataGridView dt, string ColumnName, string[] Items)
        {
            DataGridViewComboBoxColumn dataGridViewComboBoxColumn = new DataGridViewComboBoxColumn();
            for (int i = 0; i < Items.Length; i++)
            {
                dataGridViewComboBoxColumn.Items.Add(Items[i]);
            }
            dataGridViewComboBoxColumn.Name = ColumnName;
            dataGridViewComboBoxColumn.HeaderText = ColumnName;
            GridCalendarControlLib.AddComboBox(dt, dataGridViewComboBoxColumn);
        }
        public static void AddComboBox(DataGridView dt, DataGridViewComboBoxColumn col)
        {
            dt.Columns.Add(col);
        }
        public static void AddComboBox(DataGridView dt, string ColumnName, DataTable ds)
        {
            DataGridViewComboBoxColumn dataGridViewComboBoxColumn = new DataGridViewComboBoxColumn();
            dataGridViewComboBoxColumn.Name = ColumnName;
            dataGridViewComboBoxColumn.HeaderText = ColumnName;
            dataGridViewComboBoxColumn.DataSource = ds;
            dataGridViewComboBoxColumn.DisplayMember = ColumnName;
            dataGridViewComboBoxColumn.ValueMember = ColumnName;
            dataGridViewComboBoxColumn.DataPropertyName = ColumnName;
            dataGridViewComboBoxColumn.MaxDropDownItems = 20;
            dataGridViewComboBoxColumn.AutoComplete = true;
            dataGridViewComboBoxColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridViewComboBoxColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
            dataGridViewComboBoxColumn.DisplayStyleForCurrentCellOnly = false;
            dataGridViewComboBoxColumn.ReadOnly = false;
            dt.Columns.Add(dataGridViewComboBoxColumn);
        }
        public static void AddComboBox(DataGridView dt, string ColumnName, DataTable ds, string DisplayMember, string ValueMember)
        {
            GridCalendarControlLib.AddComboBox(dt, new DataGridViewComboBoxColumn
            {
                Name = ColumnName,
                HeaderText = ColumnName,
                DataSource = ds,
                DisplayMember = DisplayMember,
                ValueMember = ValueMember
            });
        }
        public static void AddComboBox(DataGridView dt, string ColumnName, string HeaderText, DataTable ds, string DisplayMember, string ValueMember)
        {
            GridCalendarControlLib.AddComboBox(dt, new DataGridViewComboBoxColumn
            {
                Name = ColumnName,
                HeaderText = HeaderText,
                DataSource = ds,
                DisplayMember = DisplayMember,
                ValueMember = ValueMember
            });
        }
        public static string TableToComboBox(ComboBox combo, DataTable table, string Value, string Key)
        {
            string result = "";
            try
            {
                combo.DataSource = table;
                combo.DisplayMember = Value;
                combo.ValueMember = Key;
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return result;
        }
        public static DataTable CreateTable(DataTable dt, string[] ColumnName)
        {
            for (int i = 0; i < ColumnName.Length; i++)
            {
                dt.Columns.Add(ColumnName[i]);
            }
            return dt;
        }
        public static DataTable DataToTable(DataTable dt, object[] value)
        {
            if (dt.Columns.Count == value.Length)
            {
                try
                {
                    dt.Rows.Add(value);
                }
                catch (Exception ex)
                {
                    string message = ex.Message;
                }
            }
            return dt;
        }
        public static DataTable GetValueChecked(DataGridView dt, DataTable table_temp)
        {
            if (table_temp.Columns.Count == 0)
            {
                string[] array = new string[dt.Columns.Count];
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    array[i] = dt.Columns[i].Name;
                }
                GridCalendarControlLib.CreateTable(table_temp, array);
            }
            for (int i = 0; i < dt.RowCount; i++)
            {
                if (dt[0, i].Value.ToString() == "1")
                {
                    byte b = 1;
                    for (int j = 0; j < table_temp.Rows.Count; j++)
                    {
                        DataRow dataRow = table_temp.Rows[j];
                        if (dataRow[1].ToString() == dt[1, i].Value.ToString())
                        {
                            b = 0;
                        }
                    }
                    if (b == 1)
                    {
                        if (GridCalendarControlLib.IsString(dt[6, i].Value.ToString()))
                        {
                            if (int.Parse(dt[6, i].Value.ToString()) > 0)
                            {
                                if (int.Parse(dt[6, i].Value.ToString()) < int.Parse(dt[3, i].Value.ToString()))
                                {
                                    object[] array2 = new object[dt.Columns.Count];
                                    for (int k = 0; k < dt.Columns.Count; k++)
                                    {
                                        array2[k] = dt[k, i].Value;
                                    }
                                    GridCalendarControlLib.DataToTable(table_temp, array2);
                                }
                                else
                                {
                                    MessageBox.Show("Xin hãy nhập số lượng mua < số lượng còn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Xin hãy nhập số lượng mua > 0", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Xin hãy nhập số lượng mua!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Vật tư này bạn dã chọn rồi!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                }
            }
            return table_temp;
        }
        public static void GetDataChecked(DataGridView dt, DataTable table_temp)
        {
            if (table_temp.Columns.Count == 0)
            {
                string[] array = new string[dt.Columns.Count];
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    array[i] = dt.Columns[i].Name;
                }
                GridCalendarControlLib.CreateTable(table_temp, array);
            }
            for (int i = 0; i < dt.RowCount; i++)
            {
                if (dt[0, i].Value.ToString() == "1")
                {
                    object[] array2 = new object[dt.Columns.Count];
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        array2[j] = dt[j, i].Value;
                    }
                    GridCalendarControlLib.DataToTable(table_temp, array2);
                }
            }
        }
        public static double Total(DataGridView dt, string ColumnName)
        {
            double num = 0.0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                num += Convert.ToDouble(dt[ColumnName, i].Value);
            }
            return num;
        }
        public static double Total(DataGridView dt, string ColumnName, bool Visible)
        {
            double num = 0.0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (Visible)
                {
                    if (dt[ColumnName, i].Visible)
                    {
                        num += Convert.ToDouble(dt[ColumnName, i].Value.ToString());
                    }
                }
                else
                {
                    num += Convert.ToDouble(dt[ColumnName, i].Value.ToString());
                }
            }
            return num;
        }
        public static double Total(DataGridView dt, string ColumnName, int Value)
        {
            double num = 0.0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (Convert.ToInt32(dt[ColumnName, i].Value) == Value)
                {
                    num += Convert.ToDouble(dt[ColumnName, i].Value.ToString());
                }
            }
            return num;
        }
        public static double TotalOrder(DataGridView dt, string ColumnName, int Value)
        {
            double num = 0.0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (Convert.ToInt32((dt[ColumnName, i].Value == "") ? 0 : dt[ColumnName, i].Value) != Value)
                {
                    num += Convert.ToDouble(dt[ColumnName, i].Value.ToString());
                }
            }
            return num;
        }
        public static double Substract(DataGridView dt, int ColumnIndex, double NumLeave)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                NumLeave -= double.Parse(dt[ColumnIndex, i].Value.ToString());
            }
            return NumLeave;
        }
        public static DataTable DeleteDataChecked(DataGridView dt, DataTable table_soure)
        {
            for (int i = 0; i < table_soure.Rows.Count; i++)
            {
                if (dt[0, i].Value.ToString() == "1")
                {
                    table_soure.Rows[i].Delete();
                    i--;
                }
            }
            return table_soure;
        }
        public static void RemoveRowsChecked(DataGridView dgv)
        {
            for (int i = 0; i < dgv.RowCount; i++)
            {
                string a = "0";
                try
                {
                    a = dgv[0, i].Value.ToString();
                }
                catch
                {
                    break;
                }
                if (a == "1")
                {
                    dgv.Rows.RemoveAt(i);
                    i--;
                }
            }
        }
        public static void RemoveRowsChecked(DataGridView dgv, int IsSave)
        {
            for (int i = 0; i < dgv.RowCount; i++)
            {
                string a = "0";
                try
                {
                    a = dgv["Chon", i].Value.ToString();
                }
                catch
                {
                }
                if (a == "1" & int.Parse(dgv["IsSave", i].Value.ToString()) == IsSave)
                {
                    dgv.Rows.RemoveAt(i);
                    i--;
                }
            }
        }
        public static void AddIndex(DataGridView dt, string Column)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt[Column, i].Value = i + 1;
            }
        }
        public static string RemoveCurrency(object Expression)
        {
            return Expression.ToString().Replace(",", "");
        }
        public static string AddCurrency(object Expression)
        {
            string text = Expression.ToString();
            string result;
            try
            {
                NumberFormatInfo numberFormat = new CultureInfo("ar-SA", false).NumberFormat;
                numberFormat.NumberDecimalDigits = 0;
                text = Convert.ToDouble(text).ToString("N", numberFormat);
                result = text;
            }
            catch (ArgumentException var_2_3D)
            {
                result = "0";
            }
            catch (OverflowException var_3_48)
            {
                result = "0";
            }
            catch (FormatException var_4_53)
            {
                result = "0";
            }
            return result;
        }
        public static string FormatCurrency(object Expression)
        {
            string expression = Expression.ToString();
            expression = GridCalendarControlLib.RemoveCurrency(expression);
            return GridCalendarControlLib.AddCurrency(expression);
        }
        public static string ChangeNum2VnStr(double num)
        {
            string text = num.ToString();
            int num2 = text.IndexOf(".") + text.IndexOf(",") + 1;
            string result;
            if (num2 > 0)
            {
                string num3 = text.Substring(0, num2);
                string num4 = (text + "00").Substring(num2 + 1, 2);
                result = GridCalendarControlLib.Num2VnStr(num3) + " phẩy " + GridCalendarControlLib.Num2VnStr(num4) + " đồng";
            }
            else
            {
                result = GridCalendarControlLib.Num2VnStr(text) + " đồng";
            }
            return result;
        }
        public static string RemoveNumberZero(string pnum)
        {
            int num = 0;
            while (pnum[num].Equals('0'))
            {
                num++;
            }
            return pnum.Substring(num, pnum.Length - num);
        }
        public static string Num2VnStr(string num)
        {
            string text = "";
            if (num.Equals("0"))
            {
                text = "không";
            }
            else
            {
                num = GridCalendarControlLib.RemoveNumberZero(num);
                if (num[0].ToString().Equals("-"))
                {
                    text = "âm ";
                    num = num.Substring(1, num.Length - 1);
                }
                if (num[0].ToString().Equals("+"))
                {
                    num = num.Substring(1, num.Length - 1);
                }
                string[] array = new string[]
				{
					"không",
					"một",
					"hai",
					"ba",
					"bốn",
					"năm",
					"sáu",
					"bảy",
					"tám",
					"chín"
				};
                string[] array2 = new string[]
				{
					"",
					"ngàn",
					"triệu",
					"tỷ"
				};
                string text2 = num;
                int length = text2.Length;
                for (int i = 0; i < length; i++)
                {
                    string text3 = "";
                    int num2 = (length - i - 1) % 3;
                    int num3 = int.Parse(text2.Substring(i, 1));
                    int num4 = num3;
                    switch (num4)
                    {
                        case 0:
                            array[0] = "";
                            if (num2 == 0 && length.Equals(1))
                            {
                                array[0] = "không";
                            }
                            else
                            {
                                if (num2 == 1)
                                {
                                    if (text2.Substring(i + 1, 1) != "0")
                                    {
                                        array[0] = "lẻ";
                                    }
                                }
                                else
                                {
                                    if (num2 == 2)
                                    {
                                        if (text2.Substring(i + 1, 1) != "0" || text2.Substring(i + 2, 1) != "0")
                                        {
                                            array[0] = "không";
                                        }
                                    }
                                }
                            }
                            break;
                        case 1:
                            if (num2 == 0 && i > 0)
                            {
                                if (text2.Substring(i - 1, 1) != "1" && text2.Substring(i - 1, 1) != "0")
                                {
                                    array[1] = "mốt";
                                }
                                else
                                {
                                    array[1] = "một";
                                }
                            }
                            else
                            {
                                if (num2 == 1)
                                {
                                    array[1] = "mười";
                                }
                                else
                                {
                                    array[1] = "một";
                                }
                            }
                            break;
                        default:
                            if (num4 == 5)
                            {
                                if (num2 == 0 && i != 0)
                                {
                                    if (text2.Substring(i - 1, 1) != "0")
                                    {
                                        array[5] = "lăm";
                                    }
                                    else
                                    {
                                        array[5] = "năm";
                                    }
                                }
                                else
                                {
                                    array[5] = "năm";
                                }
                            }
                            break;
                    }
                    switch (num2)
                    {
                        case 1:
                            if (text2.Substring(i, 1) != "1" && text2.Substring(i, 1) != "0")
                            {
                                text3 = "mươi";
                            }
                            break;
                        case 2:
                            if (i == 0)
                            {
                                text3 = "trăm";
                            }
                            else
                            {
                                if (text2.Substring(i, 1) != "0" || text2.Substring(i + 1, 1) != "0" || text2.Substring(i + 2, 1) != "0")
                                {
                                    text3 = "trăm";
                                }
                            }
                            break;
                        default:
                            {
                                int num5 = (length - i) / 3;
                                if (num5 > 3)
                                {
                                    num5 %= 3;
                                }
                                if (i > 2)
                                {
                                    if (text2.Substring(i - 2, 1) != "0" || text2.Substring(i - 1, 1) != "0" || text2.Substring(i, 1) != "0" || i == text2.Length)
                                    {
                                        text3 = array2[num5];
                                    }
                                }
                                else
                                {
                                    text3 = array2[num5];
                                }
                                break;
                            }
                    }
                    if (array[num3] == "")
                    {
                        text = text.Trim() + " " + text3;
                    }
                    else
                    {
                        text = string.Concat(new string[]
						{
							text.Trim(),
							" ",
							array[num3],
							" ",
							text3
						});
                    }
                }
            }
            return text.Trim();
        }
        public static string ToText(int Expression)
        {
            return GridCalendarControlLib.ToText(Expression.ToString());
        }
        public static string ToText(double Expression)
        {
            return GridCalendarControlLib.ToText(Expression.ToString());
        }
        public static string ToText(decimal Expression)
        {
            return GridCalendarControlLib.ToText(Expression.ToString());
        }
        public static string ToText(object Expression)
        {
            return GridCalendarControlLib.ToText(Expression.ToString());
        }
        public static string ToText(string Expression)
        {
            return GridCalendarControlLib.ToText(Expression, EnumCurrency.VND);
        }
        public static string ToText(string Expression, EnumCurrency cur)
        {
            string result;
            if (cur == EnumCurrency.USD)
            {
                result = GridCalendarControlLib.USD(Expression);
            }
            else
            {
                NumberFormatInfo numberFormat = CultureInfo.CurrentCulture.NumberFormat;
                Expression = Expression.Replace(numberFormat.NumberGroupSeparator, "");
                if (!GridCalendarControlLib.IsNumeric(Expression))
                {
                    result = "Không đọc được số";
                }
                else
                {
                    string[] array = Expression.Split(new char[]
					{
						Convert.ToChar(numberFormat.NumberDecimalSeparator)
					});
                    if (GridCalendarControlLib._Currency == "VND")
                    {
                        Expression = GridCalendarControlLib.NumToText(array[0]);
                        if (array.Length > 1)
                        {
                            string text = array[1];
                            if (text.Length >= 3)
                            {
                                if (text[0] == '0')
                                {
                                    Expression = Expression + " " + GridCalendarControlLib._currencySymbol + " phẩy không ";
                                    if (text[1] == '0')
                                    {
                                        Expression = Expression + "không " + GridCalendarControlLib.NumToText(text[2].ToString());
                                    }
                                    else
                                    {
                                        Expression += GridCalendarControlLib.NumToText(text.Substring(1, 2));
                                    }
                                }
                                else
                                {
                                    Expression = Expression + " phẩy " + GridCalendarControlLib.NumToText(text.Substring(0, 3));
                                }
                            }
                            else
                            {
                                if (text.Length == 2)
                                {
                                    if (text[0] == '0')
                                    {
                                        Expression += " phẩy không ";
                                        if (text[1] == '0')
                                        {
                                            Expression += GridCalendarControlLib.NumToText(text[1].ToString());
                                        }
                                        else
                                        {
                                            Expression += GridCalendarControlLib.NumToText(text.Substring(1, 1));
                                        }
                                    }
                                    else
                                    {
                                        Expression = string.Concat(new string[]
										{
											Expression,
											" ",
											GridCalendarControlLib._currencySymbol,
											" phẩy ",
											GridCalendarControlLib.NumToText(text.Substring(0, 2))
										});
                                    }
                                }
                                else
                                {
                                    Expression = string.Concat(new string[]
									{
										Expression,
										" ",
										GridCalendarControlLib._currencySymbol,
										" phẩy ",
										GridCalendarControlLib.NumToText(text[0].ToString())
									});
                                }
                            }
                        }
                        else
                        {
                            Expression = Expression + " " + GridCalendarControlLib._currencySymbol;
                        }
                        if (Expression.Length > 1)
                        {
                            Expression = Expression[0].ToString().ToUpper() + Expression.Substring(1);
                        }
                        result = Expression;
                    }
                    else
                    {
                        Expression = GridCalendarControlLib.NumToText(array[0]);
                        if (array.Length > 1)
                        {
                            string text = array[1];
                            if (text.Length >= 3)
                            {
                                if (text[0] == '0')
                                {
                                    Expression = Expression + " " + GridCalendarControlLib._currencySymbol + " và lẻ ";
                                    if (text[1] == '0')
                                    {
                                        Expression = Expression + "không " + GridCalendarControlLib.NumToText(text[2].ToString());
                                    }
                                    else
                                    {
                                        Expression += GridCalendarControlLib.NumToText(text.Substring(1, 2));
                                    }
                                }
                                else
                                {
                                    Expression = string.Concat(new string[]
									{
										Expression,
										" ",
										GridCalendarControlLib._currencySymbol,
										" và ",
										GridCalendarControlLib.NumToText(text.Substring(0, 3))
									});
                                }
                            }
                            else
                            {
                                if (text.Length == 2)
                                {
                                    if (text[0] == '0')
                                    {
                                        Expression = Expression + " " + GridCalendarControlLib._currencySymbol + " và lẻ ";
                                        if (text[1] == '0')
                                        {
                                            Expression += GridCalendarControlLib.NumToText(text[1].ToString());
                                        }
                                        else
                                        {
                                            Expression += GridCalendarControlLib.NumToText(text.Substring(1, 1));
                                        }
                                    }
                                    else
                                    {
                                        Expression = string.Concat(new string[]
										{
											Expression,
											" ",
											GridCalendarControlLib._currencySymbol,
											" và ",
											GridCalendarControlLib.NumToText(text.Substring(0, 2))
										});
                                    }
                                }
                                else
                                {
                                    Expression = string.Concat(new string[]
									{
										Expression,
										" ",
										GridCalendarControlLib._currencySymbol,
										" và ",
										GridCalendarControlLib.NumToText(text.Substring(0, 1))
									});
                                }
                            }
                            Expression = Expression + " " + GridCalendarControlLib._UnitSecond;
                        }
                        else
                        {
                            Expression = Expression + " " + GridCalendarControlLib._currencySymbol;
                        }
                        if (Expression.Length > 1)
                        {
                            Expression = Expression[0].ToString().ToUpper() + Expression.Substring(1);
                        }
                        result = Expression;
                    }
                }
            }
            return result;
        }
        private static string NumToText(string Expression)
        {
            string text = "";
            string text2 = "";
            NumberFormatInfo numberFormat;
            string result;
            try
            {
                numberFormat = CultureInfo.CurrentCulture.NumberFormat;
                Expression = Convert.ToInt64(Expression).ToString("##,##0");
            }
            catch (ArgumentException ex)
            {
                result = ex.Message;
                return result;
            }
            catch (OverflowException ex2)
            {
                result = ex2.Message;
                return result;
            }
            catch (FormatException ex3)
            {
                result = ex3.Message;
                return result;
            }
            string[] array = Expression.Split(new char[]
			{
				Convert.ToChar(numberFormat.NumberGroupSeparator)
			});
            int i;
            for (i = 0; i < array.Length - 3; i++)
            {
                string text3 = array[i];
                if (!text3.Equals("000"))
                {
                    for (int j = 0; j < text3.Length; j++)
                    {
                        if (j < text3.Length - 1)
                        {
                            if (int.Parse(Convert.ToString(text3[j])) == 1 && text3.Length - j - 1 == 1)
                            {
                                text = text + " " + GridCalendarControlLib.outputpostring(text3.Length - j - 1, text3[j], text3[j + 1]);
                            }
                            else
                            {
                                text = string.Concat(new string[]
								{
									text,
									" ",
									GridCalendarControlLib.outputnumberstring(text3[j], '0', j, text3.Length),
									" ",
									GridCalendarControlLib.outputpostring(text3.Length - j - 1, text3[j], text3[j + 1])
								});
                            }
                        }
                        else
                        {
                            if (text3.Length == 1)
                            {
                                text = string.Concat(new string[]
								{
									text,
									" ",
									GridCalendarControlLib.outputnumberstring(text3[j], '0', j, text3.Length),
									" ",
									GridCalendarControlLib.outputpostring(text3.Length - j - 1, text3[j], '0')
								});
                            }
                            else
                            {
                                text = string.Concat(new string[]
								{
									text,
									" ",
									GridCalendarControlLib.outputnumberstring(text3[j], text3[j - 1], j, text3.Length),
									" ",
									GridCalendarControlLib.outputpostring(text3.Length - j - 1, text3[j], '0')
								});
                            }
                        }
                    }
                    text = text.Trim();
                    text = text + " " + GridCalendarControlLib.outputgrouptring(array.Length - i - 1);
                }
            }
            while (i < array.Length)
            {
                try
                {
                    string text3 = array[i];
                    if (!text3.Equals("000"))
                    {
                        for (int j = 0; j < text3.Length; j++)
                        {
                            if (j < text3.Length - 1)
                            {
                                if (int.Parse(Convert.ToString(text3[j])) == 1 && text3.Length - j - 1 == 1)
                                {
                                    text2 = text2 + " " + GridCalendarControlLib.outputpostring(text3.Length - j - 1, text3[j], text3[j + 1]);
                                }
                                else
                                {
                                    text2 = string.Concat(new string[]
									{
										text2,
										" ",
										GridCalendarControlLib.outputnumberstring(text3[j], '0', j, text3.Length),
										" ",
										GridCalendarControlLib.outputpostring(text3.Length - j - 1, text3[j], text3[j + 1])
									});
                                }
                            }
                            else
                            {
                                if (text3.Length == 1)
                                {
                                    text2 = string.Concat(new string[]
									{
										text2,
										" ",
										GridCalendarControlLib.outputnumberstring(text3[j], '0', j, text3.Length),
										" ",
										GridCalendarControlLib.outputpostring(text3.Length - j - 1, text3[j], '0')
									});
                                }
                                else
                                {
                                    text2 = string.Concat(new string[]
									{
										text2,
										" ",
										GridCalendarControlLib.outputnumberstring(text3[j], text3[j - 1], j, text3.Length),
										" ",
										GridCalendarControlLib.outputpostring(text3.Length - j - 1, text3[j], '0')
									});
                                }
                            }
                        }
                        text2 = text2.Trim();
                        text2 = text2 + " " + GridCalendarControlLib.outputgrouptring(array.Length - i - 1);
                    }
                }
                catch (Exception var_11_530)
                {
                    result = null;
                    return result;
                }
            IL_53A:
                i++;
                continue;
                goto IL_53A;
            }
            string text4 = text + (text.Equals("") ? " " : " tỷ ") + text2;
            text4 = text4.Trim();
            result = text4;
            return result;
        }
        private static string outputnumberstring(char num, char prenum, int pos, int length)
        {
            string result;
            switch (int.Parse(Convert.ToString(num)))
            {
                case 0:
                    if (pos >= 1)
                    {
                        result = "";
                    }
                    else
                    {
                        result = "không";
                    }
                    break;
                case 1:
                    if (pos == length - 1 && int.Parse(Convert.ToString(prenum)) > 1)
                    {
                        result = "mốt";
                    }
                    else
                    {
                        result = "một";
                    }
                    break;
                case 2:
                    result = "hai";
                    break;
                case 3:
                    result = "ba";
                    break;
                case 4:
                    result = "bốn";
                    break;
                case 5:
                    if (pos == length - 1 && !prenum.Equals('0'))
                    {
                        result = "lăm";
                    }
                    else
                    {
                        result = "năm";
                    }
                    break;
                case 6:
                    result = "sáu";
                    break;
                case 7:
                    result = "bảy";
                    break;
                case 8:
                    result = "tám";
                    break;
                case 9:
                    result = "chín";
                    break;
                default:
                    result = "";
                    break;
            }
            return result;
        }
        private static string outputpostring(int pos, char num, char nextnum)
        {
            string result;
            switch (pos)
            {
                case 0:
                    result = "";
                    break;
                case 1:
                    if (int.Parse(Convert.ToString(num)) == 1)
                    {
                        result = "mười";
                    }
                    else
                    {
                        if (int.Parse(Convert.ToString(num)) == 0 && int.Parse(Convert.ToString(nextnum)) == 0)
                        {
                            result = "";
                        }
                        else
                        {
                            if (int.Parse(Convert.ToString(num)) == 0 && int.Parse(Convert.ToString(nextnum)) != 0)
                            {
                                result = "lẻ";
                            }
                            else
                            {
                                result = "mươi";
                            }
                        }
                    }
                    break;
                case 2:
                    result = "trăm";
                    break;
                default:
                    result = "";
                    break;
            }
            return result;
        }
        private static string outputgrouptring(int group)
        {
            string result;
            switch (group)
            {
                case 0:
                case 3:
                    result = "";
                    break;
                case 1:
                case 4:
                    result = "nghìn";
                    break;
                case 2:
                case 5:
                    result = "triệu";
                    break;
                default:
                    result = "";
                    break;
            }
            return result;
        }
        private static string USD(string Expression)
        {
            NumberFormatInfo numberFormat = CultureInfo.CurrentCulture.NumberFormat;
            Expression = Expression.Replace(numberFormat.NumberGroupSeparator, "");
            string result;
            if (!GridCalendarControlLib.IsNumeric(Expression))
            {
                result = "None";
            }
            else
            {
                result = GridCalendarControlLib.USD(Convert.ToDecimal(Expression));
            }
            return result;
        }
        private static string USD(decimal AMT)
        {
            NumberFormatInfo numberFormat = CultureInfo.CurrentCulture.NumberFormat;
            string text;
            if (AMT == 0m)
            {
                text = "None";
            }
            else
            {
                string[] array = new string[]
				{
					"None",
					"one",
					"two",
					"three",
					"four",
					"five",
					"six",
					"seven",
					"eight",
					"nine",
					"ten",
					"eleven",
					"twelve",
					"thirteen",
					"fourteen",
					"fifteen",
					"sixteen",
					"seventeen",
					"eighteen",
					"nineteen"
				};
                string[] array2 = new string[]
				{
					"None",
					"None",
					"twenty",
					"thirty",
					"forty",
					"fifty",
					"sixty",
					"seventy",
					"eighty",
					"ninety"
				};
                string[] array3 = new string[]
				{
					"None",
					"billion",
					"million",
					"thousand",
					"dollars",
					"cents"
				};
                if (AMT < 0m)
                {
                    text = "Minus" + new string(' ', 1);
                }
                else
                {
                    text = new string(' ', 0);
                }
                string text2 = Math.Abs(AMT).ToString("############.00");
                string text3 = new string(' ', 12) + text2;
                text2 = text3.Substring(text3.Length - 15);
                string b = numberFormat.NumberDecimalSeparator + "00";
                for (int i = 1; i <= 5; i++)
                {
                    string text4 = text2.Substring(i * 3 - 2 - 1, 3);
                    if (text4 != new string(' ', 3))
                    {
                        string text5;
                        if (text4 == "000")
                        {
                            if (i == 4 && Math.Abs(AMT) > 1m)
                            {
                                text5 = "dollars" + new string(' ', 1);
                            }
                            else
                            {
                                text5 = new string(' ', 0);
                            }
                        }
                        else
                        {
                            if (text4 == b)
                            {
                                text5 = "only";
                            }
                            else
                            {
                                long num = Convert.ToInt64(Conversion.Val(text4.Substring(0, 1)));
                                long num2 = Convert.ToInt64(Conversion.Val(text4.Substring(2, 1)));
                                long num3 = Convert.ToInt64(Conversion.Val(text4.Substring(text4.Length - 1)));
                                long num4 = Convert.ToInt64(Conversion.Val(text4.Substring(text4.Length - 2)));
                                checked
                                {
                                    if (num == 0L)
                                    {
                                        text5 = new string(' ', 0);
                                    }
                                    else
                                    {
                                        text5 = array[(int)((IntPtr)num)] + new string(' ', 1) + "hundred" + new string(' ', 1);
                                        if (num4 > 0L & num4 < 21L)
                                        {
                                            text5 = text5 + "and" + new string(' ', 1);
                                        }
                                    }
                                    if (i == 5 && Math.Abs(AMT) > 1m)
                                    {
                                        text5 = "and" + new string(' ', 1) + text5;
                                    }
                                    if (num4 < 20L & num4 > 0L)
                                    {
                                        text5 = text5 + array[(int)((IntPtr)num4)] + new string(' ', 1);
                                    }
                                    else
                                    {
                                        if (num4 >= 20L)
                                        {
                                            text5 = text5 + array2[(int)((IntPtr)num2)] + new string(' ', 1);
                                            if (num3 > 0L)
                                            {
                                                text5 = text5 + array[(int)((IntPtr)num3)] + new string(' ', 1);
                                            }
                                        }
                                    }
                                    text5 = text5 + array3[i] + new string(' ', 1);
                                }
                            }
                        }
                        text += text5;
                    }
                }
            }
            return text.Substring(0, 1).ToUpper() + text.Substring(2);
        }
        public static bool IsString(string str)
        {
            bool result;
            if (str.Length != 0)
            {
                try
                {
                    double num = 0.0;
                    result = double.TryParse(str, NumberStyles.Any, NumberFormatInfo.CurrentInfo, out num);
                    return result;
                }
                catch
                {
                    result = false;
                    return result;
                }
            }
            result = false;
            return result;
        }
        public static bool IsNumeric(object Expression)
        {
            double num;
            return double.TryParse(Convert.ToString(Expression), NumberStyles.Any, NumberFormatInfo.InvariantInfo, out num);
        }
        public static int CountCharInString(char vChar, string vString)
        {
            int num = 0;
            for (int i = 0; i < vString.Length; i++)
            {
                if (vChar == vString[i])
                {
                    num++;
                }
            }
            return num;
        }
        public static bool IsBirthDay(string vDate)
        {
            bool result;
            if (GridCalendarControlLib.IsNumeric(vDate))
            {
                result = true;
            }
            else
            {
                string[] array = new string[]
				{
					"",
					"",
					""
				};
                if (vDate.IndexOf('/') == 0)
                {
                    result = false;
                }
                else
                {
                    int num = GridCalendarControlLib.CountCharInString('/', vDate);
                    if (num == 1)
                    {
                        string[] array2 = vDate.Split(new char[]
						{
							'/'
						});
                        if (!GridCalendarControlLib.IsNumeric(array2[0]) | !GridCalendarControlLib.IsNumeric(array2[1]))
                        {
                            result = false;
                            return result;
                        }
                        num = Convert.ToInt32(array2[0]);
                        if (num < 0 | num > 12)
                        {
                            result = false;
                            return result;
                        }
                        num = Convert.ToInt32(array2[1]);
                        if (num < 0)
                        {
                            result = false;
                            return result;
                        }
                    }
                    else
                    {
                        if (num != 2)
                        {
                            result = false;
                            return result;
                        }
                        string[] array2 = vDate.Split(new char[]
						{
							'/'
						});
                        if (!GridCalendarControlLib.IsNumeric(array2[0]) | !GridCalendarControlLib.IsNumeric(array2[1]) | !GridCalendarControlLib.IsNumeric(array2[2]))
                        {
                            result = false;
                            return result;
                        }
                        num = Convert.ToInt32(array2[2]);
                        if (num < 0)
                        {
                            result = false;
                            return result;
                        }
                        num = Convert.ToInt32(array2[1]);
                        int num2 = num;
                        if (num < 0 | num > 12)
                        {
                            result = false;
                            return result;
                        }
                        num = Convert.ToInt32(array2[0]);
                        if (num < 0 | num > 31)
                        {
                            result = false;
                            return result;
                        }
                        if (num2 <= 7 & num2 % 2 == 0 & num > 30)
                        {
                            result = false;
                            return result;
                        }
                        if (num2 > 8 & num2 % 2 != 0 & num > 30)
                        {
                            result = false;
                            return result;
                        }
                        if (num2 == 2)
                        {
                            if (Convert.ToInt32(array2[2]) % 4 == 0)
                            {
                                if (num > 29)
                                {
                                    result = false;
                                    return result;
                                }
                            }
                            else
                            {
                                if (num > 28)
                                {
                                    result = false;
                                    return result;
                                }
                            }
                        }
                    }
                    result = true;
                }
            }
            return result;
        }
        public static bool IsDate(string vDate)
        {
            string[] array = new string[]
			{
				"",
				"",
				""
			};
            bool result;
            if (vDate.IndexOf('/') == 0)
            {
                result = false;
            }
            else
            {
                int num = GridCalendarControlLib.CountCharInString('/', vDate);
                if (num == 2)
                {
                    string[] array2 = vDate.Split(new char[]
					{
						'/'
					});
                    if (!GridCalendarControlLib.IsNumeric(array2[0]) | !GridCalendarControlLib.IsNumeric(array2[1]) | !GridCalendarControlLib.IsNumeric(array2[2]))
                    {
                        result = false;
                    }
                    else
                    {
                        num = Convert.ToInt32(array2[2]);
                        if (num < 0)
                        {
                            result = false;
                        }
                        else
                        {
                            num = Convert.ToInt32(array2[1]);
                            int num2 = num;
                            if (num < 0 | num > 12)
                            {
                                result = false;
                            }
                            else
                            {
                                num = Convert.ToInt32(array2[0]);
                                if (num < 0 | num > 31)
                                {
                                    result = false;
                                }
                                else
                                {
                                    if (num2 <= 7 & num2 % 2 == 0 & num > 30)
                                    {
                                        result = false;
                                    }
                                    else
                                    {
                                        if (num2 > 8 & num2 % 2 != 0 & num > 30)
                                        {
                                            result = false;
                                        }
                                        else
                                        {
                                            if (num2 == 2)
                                            {
                                                if (Convert.ToInt32(array2[2]) % 4 == 0)
                                                {
                                                    if (num > 29)
                                                    {
                                                        result = false;
                                                        return result;
                                                    }
                                                }
                                                else
                                                {
                                                    if (num > 28)
                                                    {
                                                        result = false;
                                                        return result;
                                                    }
                                                }
                                            }
                                            result = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    result = false;
                }
            }
            return result;
        }
        public static bool IsValidEmailAddress(string sEmail)
        {
            bool result;
            if (sEmail == null)
            {
                result = false;
            }
            else
            {
                int num = sEmail.IndexOf('@');
                int num2 = sEmail.LastIndexOf('@');
                if (num > 0 && num2 == num && num < sEmail.Length - 1)
                {
                    bool flag = Regex.IsMatch(sEmail, "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
                    if (flag)
                    {
                        if (sEmail[sEmail.Length - 1] == '.')
                        {
                            flag = false;
                        }
                        if (sEmail.IndexOf("..") != -1)
                        {
                            flag = false;
                        }
                        for (int i = 0; i < sEmail.Length; i++)
                        {
                            if ((sEmail[i] < 'A' || sEmail[i] > 'Z') & (sEmail[i] < 'a' || sEmail[i] > 'z') & (sEmail[i] < '0' || sEmail[i] > '9') & sEmail[i] != '@' & sEmail[i] != '.' & sEmail[i] != '_')
                            {
                                flag = false;
                                break;
                            }
                        }
                    }
                    result = flag;
                }
                else
                {
                    result = false;
                }
            }
            return result;
        }
        public static DateTime ToDate(object Expression)
        {
            DateTime dateTime = default(DateTime);
            dateTime = DateTime.Now;
            DateTime result;
            if (Expression != null)
            {
                string text = Expression.ToString();
                if (GridCalendarControlLib.IsDate(text))
                {
                    string[] array = new string[]
					{
						"0",
						"0",
						"0"
					};
                    string[] array2 = text.Split(new char[]
					{
						'/'
					});
                    dateTime = new DateTime(int.Parse(array2[2]), int.Parse(array2[1]), int.Parse(array2[0]));
                }
                result = dateTime;
            }
            else
            {
                result = dateTime;
            }
            return result;
        }
        public static double ToDouble(object expression)
        {
            string value = GridCalendarControlLib.RemoveCurrency(expression.ToString());
            return Convert.ToDouble(value);
        }
        public static int ToInt(object expression)
        {
            string value = GridCalendarControlLib.RemoveCurrency(expression.ToString());
            return Convert.ToInt32(value);
        }
        public static bool Byte_2_Bool(byte a)
        {
            return a == 1;
        }
        public static string TableToListBox(ListBox listbox, DataTable table, string Value, string Key)
        {
            string result = "";
            try
            {
                listbox.DataSource = table;
                listbox.DisplayMember = Value;
                listbox.ValueMember = Key;
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return result;
        }
        public static int BoolToInt(bool Expression)
        {
            return Expression ? 1 : 0;
        }
        public static string Get_FirstName(string sFullName)
        {
            string result = "";
            int num = sFullName.LastIndexOf(' ');
            if (num != -1)
            {
                result = sFullName.Substring(0, num);
            }
            return result;
        }
        public static string Get_LastName(string sFullName)
        {
            string result = "";
            int num = sFullName.LastIndexOf(' ');
            if (num != -1)
            {
                result = sFullName.Substring(num, sFullName.Length - num);
            }
            return result;
        }
        public static string ToTitleCase(string str)
        {
            string result;
            if (str.Length == 0)
            {
                result = str;
            }
            else
            {
                str = str.ToLower();
                char[] array = str.ToCharArray();
                array[0] = char.ToUpper(array[0]);
                foreach (Match match in Regex.Matches(str, "(\\s\\S)"))
                {
                    array[match.Index + 1] = match.Value.ToUpper().Trim()[0];
                }
                result = new string(array);
            }
            return result;
        }
        public static string ToToggleCase(string str)
        {
            string text = "";
            for (int i = 0; i < str.Length; i++)
            {
                string text2 = str[i].ToString();
                if (text2 == text2.ToLower())
                {
                    text += text2.ToUpper();
                }
                else
                {
                    text += text2.ToLower();
                }
            }
            return text;
        }
        public static string Insert(string input, string value, int startIndex, bool rightToLeft)
        {
            if (rightToLeft)
            {
                if (startIndex > input.Length)
                {
                    startIndex = 0;
                }
                else
                {
                    startIndex = input.Length - startIndex;
                }
            }
            else
            {
                if (startIndex > input.Length)
                {
                    startIndex = input.Length;
                }
            }
            return input.Insert(startIndex, value);
        }
        public static string Remove(string input, int startIndex, int count, bool rightToLeft)
        {
            string result;
            try
            {
                if (rightToLeft)
                {
                    if (startIndex > input.Length)
                    {
                        startIndex = 0;
                    }
                    else
                    {
                        startIndex = input.Length - startIndex - count;
                    }
                }
                else
                {
                    if (startIndex > input.Length)
                    {
                        startIndex = input.Length;
                    }
                }
                startIndex = ((startIndex < 0) ? 0 : startIndex);
                if (count > input.Length)
                {
                    count = input.Length;
                }
                else
                {
                    count = ((count < 0) ? 0 : count);
                }
                result = input.Remove(startIndex, count);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
        public static string Replace(string input, string oldValue, string newValue, bool matchCase)
        {
            RegexOptions options = RegexOptions.None;
            if (!matchCase)
            {
                options = RegexOptions.IgnoreCase;
            }
            Regex regex = new Regex(oldValue, options);
            input = regex.Replace(input, newValue);
            return input;
        }
        public static string RejectMarks(string text)
        {
            string result;
            if (text.Length == 0)
            {
                result = text;
            }
            else
            {
                string[] array = new string[]
				{
					"a|(á|ả|à|ạ|ã|ă|ắ|ẳ|ằ|ặ|ẵ|â|ấ|ẩ|ầ|ậ|ẫ)",
					"o|(ó|ỏ|ò|ọ|õ|ô|ố|ổ|ồ|ộ|ỗ|ơ|ớ|ở|ờ|ợ|ỡ)",
					"e|(é|è|ẻ|ẹ|ẽ|ê|ế|ề|ể|ệ|ễ)",
					"u|(ú|ù|ủ|ụ|ũ|ư|ứ|ừ|ử|ự|ữ)",
					"i|(í|ì|ỉ|ị|ĩ)",
					"y|(ý|ỳ|ỷ|ỵ|ỹ)",
					"d|đ"
				};
                for (int i = 0; i < array.Length; i++)
                {
                    char newChar = array[i][0];
                    MatchCollection matchCollection = Regex.Matches(text, array[i]);
                    foreach (Match match in matchCollection)
                    {
                        text = text.Replace(match.Value[0], newChar);
                    }
                }
                result = text;
            }
            return result;
        }
        public static string GetFirstWord(string studentName)
        {
            string text = "";
            string result;
            if (studentName.Trim().Length == 0)
            {
                result = "";
            }
            else
            {
                string[] array = studentName.Split(new char[]
				{
					' '
				});
                string[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    string text2 = array2[i];
                    if (text2.Length > 0)
                    {
                        text += text2.Substring(0, 1);
                    }
                }
                result = text;
            }
            return result;
        }
        public static string SignSoft()
        {
            return GridCalendarControlLib.SignSoft(AssemblyHelper.AssemblyTitle);
        }
        public static string SignSoft(string softname)
        {
            return GridCalendarControlLib.GetFirstWord(GridCalendarControlLib.RejectMarks(softname)).ToUpper();
        }
        public static bool IsAddressAvailable(string address)
        {
            Ping ping = new Ping();
            bool result;
            try
            {
                result = (ping.Send(address, 100).Status == IPStatus.Success);
            }
            catch
            {
                result = false;
            }
            return result;
        }
    }
}
